#include <stdio.h>
#include <assert.h>

#include "halofinder.h"

size_t fwrite_fortran(const void *ptr, size_t size, size_t nitems, FILE *stream)
{
  size_t nwrite;
  int num;
  
  num = size*nitems;
  nwrite = fwrite(&num,sizeof(int),(size_t) 1,stream);
  assert(nwrite == 1);
  
  nwrite = fwrite(ptr,size,nitems,stream);
  assert(nwrite == nitems);
  
  num = size*nitems;
  nwrite = fwrite(&num,sizeof(int),(size_t) 1,stream);
  assert(nwrite == 1);
  
  return nitems;
}

size_t fread_fortran(void *ptr, size_t size, size_t nitems, FILE *stream)
{
  size_t nread;
  int num1,num2;
  
  nread = fread(&num1,sizeof(int),(size_t) 1,stream);
  assert(nread == 1);
  
  nread = fread(ptr,size,nitems,stream);
  assert(nread == nitems);
  
  nread = fread(&num2,sizeof(int),(size_t) 1,stream);
  assert(nread == 1);
  
  assert(num1 == num2);
  assert(((size_t) num1) == size*nitems);
  
  return nitems;
}
